package cn.jhc.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.jhc.bean.ShopBean;
import cn.jhc.bean.UserBean;
import cn.jhc.dao.ShopDAO;
@WebServlet(name="Check list",urlPatterns={"/checklist.do"})
public class ChecklistServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	HttpSession session=req.getSession();
	List<ShopBean> list = new ArrayList<ShopBean>();
	UserBean users = (UserBean) session.getAttribute("user");
	ShopDAO dao=null;
	if (null != users) {
		dao=new ShopDAO();
		String user=users.getDisplayname();
		try{
		list=dao.Checklist(user);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		if(list.size()==0){
			RequestDispatcher dispatcher = req.getRequestDispatcher("/JiTa.jsp");
			dispatcher.forward(req, resp);
			return;
		}
		else{
	req.setAttribute("list", list);
		RequestDispatcher dispatcher = req.getRequestDispatcher("/checklist.jsp");
		dispatcher.forward(req, resp);
		return;
		}
	}
	else{
		String getb=(String)req.getParameter("getb");
		req.setAttribute("getb", getb);
		RequestDispatcher dispatcher = req.getRequestDispatcher("/login.jsp");
		dispatcher.forward(req, resp);
		return;
	}
}
@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
}
